/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-09-06
 * Time: 22:03
 */
public class Test {
    class Solution {
        static class TreeNode{
            TreeNode left;
            TreeNode right;
            TreeNode root;
            int val;
            public TreeNode(){
                this.val = val;
            }
        }
        public boolean isSubtree(TreeNode root, TreeNode subRoot) {
            if(root == null){
                return false;
            }
            if(isSameTree(root, subRoot)) return true;
            if(isSubtree(root.left, subRoot)) return true;
            if(isSubtree(root.right , subRoot)) return true;

            return false;
        }


        public boolean isSameTree(TreeNode p, TreeNode q) {
            //1.先判断结构是否相同
            if(p != null && q == null || p == null && q != null){
                return false;
            }
            //2.剩下的两种情况为 空或者相等
            if(p == null && q == null){
                return true;
            }
            //都不为空，判断值是否一样
            if(p.val != q.val){
                return false;
            }
            //都不为空且值一样
            return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }

    }
}
